import Vue from 'vue'
import Vuex from 'vuex'
import http from '../common/http.js'

Vue.use(Vuex)

const store = new Vuex.Store({
	state:{
		loginImg:'',//logo
		member:{},//个人设置信息
		statusBarHeight:0,//设备高度
		routeList:[],//路由数据h5放弃路由取参数
		routeOption:{} ,//当前参数
	},
	getters:{
		getmember:(state)=>{
			return state.member
		},
	},
	mutations:{
		//登录图片logo
		getLoginImg:(state,num)=>{
			http.sendrequest('/login/LoginImage').then(res=>{
				if(res.code == 1) state.loginImg = res.data
				else state.loginImg = '../../static/img/02.webp'
			})
		},
		// 获取个人设备状态栏
		getTabHeight:(state,num)=>{
			state.statusBarHeight = num*2;
		},
		//获取路由导航
		getRoute(state,data){
			state.routeList = data.map(item=>{
				let obj = {
					path:item.path,
					option:''
				}
				return obj;
			})
		},
		//更改存储的参数
		setRoute(state,data){
			state.routeList.forEach(item=>{
				if(item.path.indexOf(data.path) != -1) {
					item.option = JSON.parse(JSON.stringify(data.option));
				}
			})
		},
		// 修改当前route携带的参数
		getRouteOption:(state)=>{
			let url = location.pathname;
			try{
				state.routeList.forEach(item=>{
					if(item.path != '/' && url.indexOf(item.path) != -1){
						 state.routeOption = item.option
						 throw false
					}
				})
			}catch(err){}
		}
	},
	actions:{
		/**
		 * @param {Object} 异步操作需要提交同步（mutations），再到同步（mutations）上面更改
		 */
		numAction(context,num){
			context.commit('numAction',num)
		},
	},
	
})

export default store;